// historypage.h
#ifndef HISTORYPAGE_H
#define HISTORYPAGE_H

#include "receive_processor.h"
#include "databasemanager.h"

#include <QWidget>
#include <QSqlTableModel>
#include <QDateTimeEdit>
#include <QTableView>
#include <QPushButton>
#include <QFile>
#include <QFileDialog>
#include <QAxObject>
#include <QLabel>
#include <QListWidget>
#include <QListWidgetItem>


class QTableView;
class QLineEdit;
class QComboBox;
class QDateTimeEdit;
class QPushButton;

class HistoryPage : public QWidget
{
    Q_OBJECT
public:
    explicit HistoryPage(QWidget *parent = nullptr);

public slots:
    void insert_Data(QList<Receive_Processor*>*receive_processors,int index);
    void setupUI(QList<Receive_Processor*>*receive_processors);
private slots:
    void onSearch();
    void onDelete();
    void onClear();
    // void onAddTestData();
    void on_currentChanged(const QModelIndex &current, const QModelIndex &previous);
    void on_currentRowChanged(const QModelIndex &current, const QModelIndex &previous);
    void exportSelectedToCSV();//导出到CSV文件中
    void exportToExcel();//导出到HTML文件
    void exportSelectedToExcel();//导出到excel文件
    void export_to_data_analysis();//将选中的数据用于数据分析
    void select_all();
    void select_not_all();
    void change_device_table(QString);//更换当前显示的设备的数据表
private:

    void setupModel(QString);
    void Check_Database();
    // void Check_Database(QSqlDatabase db);
    bool tableExists(const QString& tableName);

    QSqlTableModel *model;
    QItemSelectionModel *theSelection;
    QDateTimeEdit *startTimeEdit;
    QDateTimeEdit *endTimeEdit;
    QComboBox *typeCombo;
    QComboBox *device_combo;
    QTableView *tableView;

    QPushButton *searchButton;
    QPushButton *deleteButton;
    QPushButton *clearButton;
    QPushButton *testDataButton;
    QPushButton *export_to_csv;
    QPushButton *export_to_html;
    QPushButton*export_to_excel;
    QPushButton *export_to_data_analysis_button;
    QList<QString> *device_address;
    QListWidget *param_select_list;
    QList<QListWidgetItem*>* param_item_list;
};

#endif // HISTORYPAGE_H
